<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选项卡</title>
    <script src="js/vue.js"></script>
    <style>
            *{
                margin: 0;
                padding: 0;
                list-style: none;
            }
            .menu{
                height: 40px;
                display: flex;
            }
            .menu .item {
                flex: 1;
                text-align: center;
                line-height: 40px;
                background-color: black;
                color:white;

            }
            .menu  .active{
                background-color: red;
            }
    </style>
</head>
<body>
    <div id="app">
        <div class="menu">
                <div class="item" :class="{active:activeIndex==item.id}" v-for="item in list" @click="changeIndex(item.id)"> {{item.msg}}</div>
        </div>

    </div>
</body>
<script>
    new  Vue({
        el:"#app",
        data:{
            activeIndex:1,
            list:[{id:1,msg:"菜单一"},{id:2,msg:"菜单二"},{id:3,msg:"菜单三"},{id:4,msg:"菜单四"}]
        },
        methods:{
            changeIndex(id){
                this.activeIndex = id;
            }
        }
    })

</script>
</html>